import request from '@/plugins/request'
import { IResponseData } from '@/types/request-base'
import { json2FormData } from '@/utils'
// 经销商收货地址变更

/**
 * 查询变更单收货地址
 * @param {String} changeId  变更单ID
 */
export function getCustomerAddress(changeId: string) {
  return request<IResponseData>({
    method: 'get',
    url: `/app/v1/ctmCustomerAddress?changeId=${changeId}`,
    loading: true
  })
}

/**
 * 查询变更单收货地址原始数据(来自MDM)
 * @param {String} changeId  变更单ID
 * @param {Number} contactScope 范围：1 经销商联系人， 3 门店联系人
 */
export function getMdmCustomerAddress(changeId: string) {
  return request<IResponseData>({
    method: 'get',
    url: `/app/v1/ctmCustomerAddress/mdm/address?changeId=${changeId}`
  })
}

/**
 * 保存收货地址
 * @param {Array} data 列表数据
 * @param {String} changeCode 变更单编码
 */
export function saveAddress(data: any, changeCode: string) {
  return request<IResponseData>({
    method: 'post',
    url: `/app/v1/ctmCustomerChange/insertOrUpdate/address?changeCode=${changeCode}`,
    data,
    loading: true,
    headers: {
      repeatSubmit: false
    }
  })
}
